<template>
	<view class="ai-summary-container">
		<!-- 顶部状态栏占位 -->
		<view class="status-bar" :style="{ height: statusBarHeight + 'px' }"></view>
		
		<!-- 头部区域 -->
		<view class="header-section">
			<view class="header-bar">
				<view class="back-button" @click="goBack">
					<text class="back-icon"><</text>
				</view>
				<text class="header-title">AI智能总结</text>
				<view class="header-actions">
					<view class="header-action" @click="generateSummary">
						<text class="action-text">生成总结</text>
					</view>
				</view>
			</view>
		</view>
		
		<!-- 总结选项 -->
		<view class="summary-options">
			<view class="option-header">
				<text class="option-title">选择总结类型</text>
			</view>
			<view class="options-grid">
				<view 
					v-for="option in summaryOptions" 
					:key="option.key"
					class="option-card"
					:class="{ active: selectedOption === option.key }"
					@click="selectOption(option.key)"
				>
					<text class="option-icon">{{ option.icon }}</text>
					<text class="option-label">{{ option.label }}</text>
					<text class="option-desc">{{ option.description }}</text>
				</view>
			</view>
		</view>
		
		<!-- 自定义日期范围选择 -->
		<view v-if="selectedOption === 'custom'" class="custom-date-section">
			<view class="date-picker-row">
				<view class="date-picker-item">
					<text class="date-label">开始日期</text>
					<picker mode="date" :value="customStartDate" @change="onStartDateChange">
						<view class="date-picker-input">
							<text class="date-text">{{ customStartDate || '选择开始日期' }}</text>
							<text class="picker-arrow">📅</text>
						</view>
					</picker>
				</view>
				<view class="date-picker-item">
					<text class="date-label">结束日期</text>
					<picker mode="date" :value="customEndDate" @change="onEndDateChange">
						<view class="date-picker-input">
							<text class="date-text">{{ customEndDate || '选择结束日期' }}</text>
							<text class="picker-arrow">📅</text>
						</view>
					</picker>
				</view>
			</view>
		</view>
		
		<!-- 总结内容 -->
		<view class="summary-content">
			<!-- 加载状态 -->
			<view v-if="loading" class="loading-state">
				<view class="loading-animation">
					<view class="loading-circle"></view>
					<view class="loading-dots">
						<view class="dot dot1"></view>
						<view class="dot dot2"></view>
						<view class="dot dot3"></view>
					</view>
				</view>
				<text class="loading-text">AI正在分析您的待办事项...</text>
				<text class="loading-tip">这可能需要30-90秒，请耐心等待</text>
			</view>
			
			<!-- 总结结果 -->
			<view v-else-if="summaryResult" class="summary-result">
				<view class="result-header">
					<text class="result-icon">🤖</text>
					<text class="result-title">AI分析报告</text>
					<!-- <text class="result-time">{{ formatTime(summaryResult.generatedAt) }}</text> -->
					<view class="result-meta">
						<text class="meta-tag">{{ getSummaryTypeText() }}</text>
						<text class="meta-date">{{ getSummaryDateText() }}</text>
					</view>
				</view>
				
				<view class="result-content">
					<!-- 待办统计 -->
					<view v-if="summaryResult.stats" class="summary-section">
						<text class="section-title">📊 待办概览</text>
						<view class="stats-grid">
							<view class="stat-item">
								<text class="stat-number">{{ summaryResult.stats.total || 0 }}</text>
								<text class="stat-label">总待办</text>
							</view>
							<view class="stat-item">
								<text class="stat-number">{{ summaryResult.stats.completed || 0 }}</text>
								<text class="stat-label">已完成</text>
							</view>
							<view class="stat-item">
								<text class="stat-number">{{ summaryResult.stats.pending || 0 }}</text>
								<text class="stat-label">待完成</text>
							</view>
							<view class="stat-item">
								<text class="stat-number">{{ summaryResult.stats.completionRate || 0 }}%</text>
								<text class="stat-label">完成率</text>
							</view>
						</view>
					</view>
					
					<!-- AI分析内容 -->
					<view class="summary-section">
						<text class="section-title">🔍 智能分析</text>
						<view class="analysis-content">
							<rich-text 
								class="analysis-rich-text" 
								:nodes="getFormattedSummary()"
							></rich-text>
						</view>
					</view>
				</view>
				
				<view class="action-buttons">
					<view class="action-btn secondary" @click="copyResult">
						<text class="btn-text">📋 复制分析</text>
					</view>
					<view class="action-btn primary" @click="generateSummary">
						<text class="btn-text">🔄 重新生成</text>
					</view>
				</view>
			</view>
			
			<!-- 错误状态 -->
			<view v-else-if="errorMessage" class="error-state">
				<view class="error-icon">⚠️</view>
				<text class="error-title">生成失败</text>
				<text class="error-message">{{ errorMessage }}</text>
				<view class="error-action" @click="generateSummary">
					<text class="error-action-text">重试</text>
				</view>
			</view>
			
			<!-- 空状态 -->
			<view v-else class="empty-state">
				<view class="empty-icon">🤖</view>
				<text class="empty-title">AI助手就绪</text>
				<text class="empty-subtitle">选择总结类型并点击"生成总结"开始分析</text>
				<view class="empty-action" @click="generateSummary">
					<text class="empty-action-text">开始分析</text>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
import { generateDailySummary, generateWeeklySummary, generateCustomSummary } from '../../api/ai.js'
import { getTodoStatistics, getTodosByDate, getTodoList } from '../../api/todo.js'

export default {
	data() {
		return {
			statusBarHeight: 0,
			selectedOption: 'today',
			loading: false,
			summaryResult: null,
			errorMessage: '',
			customStartDate: '',
			customEndDate: '',

			summaryOptions: [
				{
					key: 'today',
					label: '今日总结',
					icon: '📅',
					description: '分析今天的待办完成情况'
				},
				{
					key: 'week',
					label: '本周总结',
					icon: '📊',
					description: '回顾本周的工作表现'
				},
				{
					key: 'custom',
					label: '自定义范围',
					icon: '🔍',
					description: '选择特定日期范围分析'
				}
			]
		}
	},
	
	onLoad() {
		console.log('AI总结页面加载成功');
		// 获取状态栏高度
		const systemInfo = uni.getSystemInfoSync();
		this.statusBarHeight = systemInfo.statusBarHeight;
		
		// 初始化自定义日期
		this.initCustomDates();
	},
	
	onShow() {
		console.log('AI总结页面显示');
	},
	
	methods: {
		// 返回上一页
		goBack() {
			console.log('点击返回按钮');
			uni.navigateBack();
		},
		
		// 选择总结选项
		selectOption(key) {
			this.selectedOption = key;
			this.errorMessage = '';
			console.log('选择总结类型:', key);
		},
		
		// 处理API响应数据
		async processApiResponse(apiData) {
			console.log('处理API响应数据:', apiData);
			
			// 获取真实的任务统计数据
			const stats = await this.fetchTaskStats();
			
			// 解析AI返回的文本，尝试提取建议
			const suggestions = this.extractSuggestions(apiData.summary);
			
			const result = {
				stats: stats,
				summary: apiData.summary || '暂无分析内容',
				suggestions: suggestions,
				type: this.selectedOption,
				date: apiData.date,
				startDate: apiData.startDate,
				endDate: apiData.endDate,
				generatedAt: apiData.generatedAt || Date.now()
			};
			
			console.log('处理后的结果数据:', result);
			return result;
		},
		
		// 获取真实的待办统计数据
		async fetchTaskStats() {
			try {
				// 根据总结类型获取对应时间范围的待办统计
				const stats = await this.getTaskStatsByType();
				console.log('获取到的待办统计:', stats);
				return stats;
			} catch (error) {
				console.error('获取待办统计失败，使用默认数据:', error);
				// 返回默认统计数据
				return {
					total: 0,
					completed: 0,
					pending: 0,
					completionRate: 0
				};
			}
		},
		
		// 根据总结类型获取对应的待办统计
		async getTaskStatsByType() {
			console.log('获取待办统计 - 总结类型:', this.selectedOption);
			
			// 参照todo-ui的逻辑，根据不同的总结类型获取对应的统计数据
			switch (this.selectedOption) {
				case 'today':
					return await this.getTodayStats();
				case 'week':
					return await this.getWeekStats();
				case 'custom':
					return await this.getCustomRangeStats();
				default:
					return await this.getAllTaskStats();
			}
		},
		
		// 获取今日待办统计（参照todo-ui逻辑）
		async getTodayStats() {
			try {
				// 获取今日待办
				const today = this.formatDate(new Date());
				const response = await getTodosByDate(today);
				
				if (response && response.code === 200) {
					const todayTasks = response.data || [];
					console.log('今日待办:', todayTasks);
					
					const totalCount = todayTasks.length;
					const completedCount = todayTasks.filter(task => task.status === 1).length;
					const pendingCount = todayTasks.filter(task => task.status === 0).length;
					const completionRate = totalCount > 0 ? Math.round((completedCount / totalCount) * 100) : 0;
					
					return {
						total: totalCount,
						completed: completedCount,
						pending: pendingCount,
						completionRate: completionRate,
						dateLabel: '今日待办'
					};
				}
				
				// 如果获取今日待办失败，降级到全部统计
				return await this.getAllTaskStats();
			} catch (error) {
				console.error('获取今日统计失败:', error);
				return await this.getAllTaskStats();
			}
		},
		
		// 获取本周待办统计
		async getWeekStats() {
			try {
				// 获取本周日期范围
				const today = new Date();
				const weekStart = new Date(today.getTime() - 6 * 24 * 60 * 60 * 1000);
				const startDate = this.formatDate(weekStart);
				const endDate = this.formatDate(today);
				
				console.log('本周统计 - 日期范围:', startDate, '到', endDate);
				
				// 获取本周所有待办
				const weekTasks = await this.getTasksInDateRange(startDate, endDate);
				
				const totalCount = weekTasks.length;
				const completedCount = weekTasks.filter(task => task.status === 1).length;
				const pendingCount = weekTasks.filter(task => task.status === 0).length;
				const completionRate = totalCount > 0 ? Math.round((completedCount / totalCount) * 100) : 0;
				
				return {
					total: totalCount,
					completed: completedCount,
					pending: pendingCount,
					completionRate: completionRate,
					dateLabel: '本周待办'
				};
			} catch (error) {
				console.error('获取本周统计失败:', error);
				return await this.getAllTaskStats();
			}
		},
		
		// 获取自定义日期范围统计
		async getCustomRangeStats() {
			try {
				if (!this.customStartDate || !this.customEndDate) {
					return await this.getAllTaskStats();
				}
				
				console.log('自定义统计 - 日期范围:', this.customStartDate, '到', this.customEndDate);
				
				// 获取自定义日期范围内的待办
				const customTasks = await this.getTasksInDateRange(this.customStartDate, this.customEndDate);
				
				const totalCount = customTasks.length;
				const completedCount = customTasks.filter(task => task.status === 1).length;
				const pendingCount = customTasks.filter(task => task.status === 0).length;
				const completionRate = totalCount > 0 ? Math.round((completedCount / totalCount) * 100) : 0;
				
				// 生成日期标签
				const dateLabel = this.customStartDate === this.customEndDate 
					? `${this.customStartDate}待办`
					: `${this.customStartDate}至${this.customEndDate}待办`;
				
				return {
					total: totalCount,
					completed: completedCount,
					pending: pendingCount,
					completionRate: completionRate,
					dateLabel: dateLabel
				};
			} catch (error) {
				console.error('获取自定义范围统计失败:', error);
				return await this.getAllTaskStats();
			}
		},
		
		// 获取全部待办统计（参照todo-ui逻辑）
		async getAllTaskStats() {
			const response = await getTodoStatistics();
			
			if (response && response.code === 200) {
				const data = response.data;
				console.log('全部待办统计API响应:', data);
				
				// 使用后端返回的字段名
				const total = data.totalCount || 0;
				const completed = data.completedCount || 0;
				const pending = data.pendingCount || 0;
				const today = data.todayCount || 0;
				const completionRate = total > 0 ? Math.round((completed / total) * 100) : 0;
				
				return {
					total: total,
					completed: completed,
					pending: pending,
					today: today,
					completionRate: completionRate,
					dateLabel: '全部待办'
				};
			} else {
				throw new Error('API响应格式错误');
			}
		},
		

		
		// 获取指定日期范围内的待办
		async getTasksInDateRange(startDate, endDate) {
			// 如果是同一天，直接调用按日期获取的API
			if (startDate === endDate) {
				const response = await getTodosByDate(startDate);
				if (response && response.code === 200) {
					return response.data || [];
				}
				return [];
			}
			
			// 如果是日期范围，需要获取所有待办然后筛选
			const response = await getTodoList();
			if (response && response.code === 200) {
				const allTasks = response.data || [];
				console.log('获取到的所有待办:', allTasks);
				
				// 筛选指定日期范围内的待办
				const filteredTasks = allTasks.filter(task => {
					if (!task.dueDate) return false;
					const taskDate = task.dueDate;
					console.log(`待办 "${task.title}" 的截止日期: ${taskDate}, 范围: ${startDate} - ${endDate}`);
					return taskDate >= startDate && taskDate <= endDate;
				});
				
				console.log('筛选后的待办:', filteredTasks);
				return filteredTasks;
			}
			return [];
		},
		
		// 从AI文本中提取建议
		extractSuggestions(summaryText) {
			if (!summaryText) return [];
			
			// 尝试从AI文本中提取建议
			const suggestions = [];
			
			// 查找常见的建议模式
			const suggestionPatterns = [
				/建议[：:]\s*(.+?)(?=[。\n]|$)/g,
				/推荐[：:]\s*(.+?)(?=[。\n]|$)/g,
				/可以[：:]?\s*(.+?)(?=[。\n]|$)/g,
				/应该[：:]?\s*(.+?)(?=[。\n]|$)/g,
				/\d+[\.、]\s*(.+?)(?=[。\n]|$)/g
			];
			
			suggestionPatterns.forEach(pattern => {
				let match;
				while ((match = pattern.exec(summaryText)) !== null) {
					const suggestion = match[1].trim();
					if (suggestion.length > 5 && suggestion.length < 100) {
						suggestions.push(suggestion);
					}
				}
			});
			
			// 如果没有提取到建议，返回通用建议
			if (suggestions.length === 0) {
				return [
					'继续保持良好的待办管理习惯',
					'定期回顾和调整待办优先级',
					'合理安排时间，避免待办堆积',
					'保持工作与生活的平衡'
				];
			}
			
			// 去重并限制数量
			return [...new Set(suggestions)].slice(0, 4);
		},
		
		// 格式化总结内容，支持Markdown
		getFormattedSummary() {
			if (!this.summaryResult || !this.summaryResult.summary) {
				return '暂无分析内容';
			}
			
			try {
				// 使用自定义的简单Markdown解析器
				const htmlContent = this.parseMarkdown(this.summaryResult.summary);
				return htmlContent;
			} catch (error) {
				console.error('Markdown解析失败:', error);
				// 如果解析失败，返回原始文本
				return this.summaryResult.summary || '暂无分析内容';
			}
		},
		
		// 自定义简单Markdown解析器（兼容uni-app）
		parseMarkdown(text) {
			if (!text) return '';
			
			// 按行分割处理
			const lines = text.split('\n');
			const result = [];
			let inList = false;
			let listItems = [];
			
			for (let i = 0; i < lines.length; i++) {
				let line = lines[i];
				
				// 处理标题
				if (line.startsWith('### ')) {
					if (inList) {
						result.push('<ul>' + listItems.join('') + '</ul>');
						listItems = [];
						inList = false;
					}
					result.push('<h3>' + line.substring(4) + '</h3>');
				} else if (line.startsWith('## ')) {
					if (inList) {
						result.push('<ul>' + listItems.join('') + '</ul>');
						listItems = [];
						inList = false;
					}
					result.push('<h2>' + line.substring(3) + '</h2>');
				} else if (line.startsWith('# ')) {
					if (inList) {
						result.push('<ul>' + listItems.join('') + '</ul>');
						listItems = [];
						inList = false;
					}
					result.push('<h1>' + line.substring(2) + '</h1>');
				}
				// 处理无序列表
				else if (line.startsWith('- ')) {
					const listContent = this.formatInlineMarkdown(line.substring(2));
					listItems.push('<li>' + listContent + '</li>');
					inList = true;
				}
				// 处理有序列表
				else if (/^\d+\. /.test(line)) {
					const listContent = this.formatInlineMarkdown(line.replace(/^\d+\. /, ''));
					listItems.push('<li>' + listContent + '</li>');
					inList = true;
				}
				// 处理引用
				else if (line.startsWith('> ')) {
					if (inList) {
						result.push('<ul>' + listItems.join('') + '</ul>');
						listItems = [];
						inList = false;
					}
					const quoteContent = this.formatInlineMarkdown(line.substring(2));
					result.push('<blockquote>' + quoteContent + '</blockquote>');
				}
				// 处理分割线
				else if (line.trim() === '---') {
					if (inList) {
						result.push('<ul>' + listItems.join('') + '</ul>');
						listItems = [];
						inList = false;
					}
					result.push('<hr>');
				}
				// 处理空行
				else if (line.trim() === '') {
					if (inList) {
						result.push('<ul>' + listItems.join('') + '</ul>');
						listItems = [];
						inList = false;
					}
					// 空行作为段落分隔
				}
				// 处理普通段落
				else {
					if (inList) {
						result.push('<ul>' + listItems.join('') + '</ul>');
						listItems = [];
						inList = false;
					}
					const formattedLine = this.formatInlineMarkdown(line);
					result.push('<p>' + formattedLine + '</p>');
				}
			}
			
			// 处理最后的列表
			if (inList && listItems.length > 0) {
				result.push('<ul>' + listItems.join('') + '</ul>');
			}
			
			return result.join('');
		},
		
		// 处理行内Markdown格式
		formatInlineMarkdown(text) {
			if (!text) return '';
			
			// 转义HTML特殊字符
			let formatted = text.replace(/&/g, '&amp;')
							   .replace(/</g, '&lt;')
							   .replace(/>/g, '&gt;');
			
			// 先处理行内代码 `code` (避免代码内的*被处理)
			const codeBlocks = [];
			formatted = formatted.replace(/`(.*?)`/g, function(match, content) {
				const placeholder = `__CODE_BLOCK_${codeBlocks.length}__`;
				codeBlocks.push('<code>' + content + '</code>');
				return placeholder;
			});
			
			// 处理粗体 **text**
			formatted = formatted.replace(/\*\*(.*?)\*\*/g, '<strong>$1</strong>');
			
			// 处理斜体 *text* (简化处理，先移除已处理的粗体标记)
			formatted = formatted.replace(/\*([^*\n]+?)\*/g, function(match, content) {
				// 简单检查：如果内容中包含strong标签，说明可能是粗体的一部分，跳过
				if (content.includes('<strong>') || content.includes('</strong>')) {
					return match;
				}
				return '<em>' + content + '</em>';
			});
			
			// 恢复代码块
			codeBlocks.forEach((code, index) => {
				formatted = formatted.replace(`__CODE_BLOCK_${index}__`, code);
			});
			
			return formatted;
		},
		
		// 初始化自定义日期
		initCustomDates() {
			const today = new Date();
			const weekAgo = new Date(today.getTime() - 7 * 24 * 60 * 60 * 1000);
			
			this.customEndDate = this.formatDate(today);
			this.customStartDate = this.formatDate(weekAgo);
		},
		
		// 开始日期变化
		onStartDateChange(e) {
			this.customStartDate = e.detail.value;
			console.log('开始日期:', this.customStartDate);
		},
		
		// 结束日期变化
		onEndDateChange(e) {
			this.customEndDate = e.detail.value;
			console.log('结束日期:', this.customEndDate);
		},
		
		// 生成AI总结
		async generateSummary() {
			console.log('开始生成总结，类型:', this.selectedOption);
			
			// 验证自定义日期范围
			if (this.selectedOption === 'custom') {
				if (!this.customStartDate || !this.customEndDate) {
					uni.showToast({
						title: '请选择日期范围',
						icon: 'none',
						duration: 2000
					});
					return;
				}
				
				if (new Date(this.customStartDate) > new Date(this.customEndDate)) {
					uni.showToast({
						title: '开始日期不能晚于结束日期',
						icon: 'none',
						duration: 2000
					});
					return;
				}
			}
			
			this.loading = true;
			this.errorMessage = '';
			this.summaryResult = null;
			

			try {
				let response;
				
				// 根据选择的类型调用不同的API
				switch (this.selectedOption) {
					case 'today':
						console.log('调用今日总结API');
						response = await generateDailySummary();
						break;
					case 'week':
						console.log('调用本周总结API');
						response = await generateWeeklySummary();
						break;
					case 'custom':
						console.log('调用自定义总结API', this.customStartDate, this.customEndDate);
						response = await generateCustomSummary(this.customStartDate, this.customEndDate);
						break;
				}
				
				console.log('API响应:', response);
				
				if (response && response.code === 200) {
					// 处理API返回的数据，补充前端需要的结构化信息
					this.summaryResult = await this.processApiResponse(response.data);
					
					uni.showToast({
						title: '分析完成',
						icon: 'success',
						duration: 2000
					});
				} else {
					throw new Error(response?.message || '生成失败');
				}
			} catch (error) {
				console.error('生成总结失败:', error);
				this.errorMessage = error.message || '网络错误，请检查连接后重试';
				
				uni.showToast({
					title: '生成总结失败，请稍后重试',
					icon: 'error',
					duration: 2000
				});
			} finally {
				this.loading = false;
			}
		},
		
		// 格式化日期
		formatDate(date) {
			const d = new Date(date);
			const year = d.getFullYear();
			const month = String(d.getMonth() + 1).padStart(2, '0');
			const day = String(d.getDate()).padStart(2, '0');
			return `${year}-${month}-${day}`;
		},
		
		// 格式化时间
		formatTime(timestamp) {
			if (!timestamp) return '';
			const date = new Date(timestamp);
			return date.toLocaleString('zh-CN', {
				month: '2-digit',
				day: '2-digit',
				hour: '2-digit',
				minute: '2-digit'
			});
		},
		
		// 获取总结类型文本
		getSummaryTypeText() {
			const typeMap = {
				today: '今日总结',
				week: '本周总结',
				custom: '自定义总结'
			};
			return typeMap[this.summaryResult?.type] || '';
		},
		
		// 获取总结日期文本
		getSummaryDateText() {
			if (!this.summaryResult) return '';
			
			const { type, date, startDate, endDate } = this.summaryResult;
			
			switch (type) {
				case 'today':
					return date || this.formatDate(new Date());
				case 'week':
					const today = new Date();
					const weekStart = new Date(today.getTime() - 6 * 24 * 60 * 60 * 1000);
					return `${this.formatDate(weekStart)} ~ ${this.formatDate(today)}`;
				case 'custom':
					return `${startDate} ~ ${endDate}`;
				default:
					return '';
			}
		},
		
		// 复制结果
		copyResult() {
			if (!this.summaryResult) return;
			
			let text = `🤖 AI智能分析报告\n\n`;
			
			// 添加统计信息
			if (this.summaryResult.stats) {
				text += `📊 待办概览\n`;
				text += `总待办: ${this.summaryResult.stats.total}\n`;
				text += `已完成: ${this.summaryResult.stats.completed}\n`;
				text += `待完成: ${this.summaryResult.stats.pending}\n`;
				text += `完成率: ${this.summaryResult.stats.completionRate}%\n\n`;
			}
			
			// 添加分析内容（保持原始Markdown格式）
			text += `🔍 智能分析\n`;
			text += `${this.summaryResult.summary || this.summaryResult.analysis || '暂无分析内容'}\n\n`;
			
			text += `生成时间: ${this.formatTime(this.summaryResult.generatedAt)}`;
			
			uni.setClipboardData({
				data: text,
				success: () => {
					uni.showToast({
						title: '已复制到剪贴板（含Markdown格式）',
						icon: 'success',
						duration: 2000
					});
				},
				fail: () => {
					uni.showToast({
						title: '复制失败',
						icon: 'none',
						duration: 2000
					});
				}
			});
		}
	}
}
</script>

<style scoped>
.ai-summary-container {
	min-height: 100vh;
	height: 100vh;
	background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
	padding-bottom: env(safe-area-inset-bottom);
	display: flex;
	flex-direction: column;
	overflow: hidden;
}

.status-bar {
	background: transparent;
}

.header-section {
	padding: 20rpx;
	flex-shrink: 0;
}

.header-bar {
	display: flex;
	align-items: center;
	justify-content: space-between;
}

.back-button {
	width: 80rpx;
	height: 80rpx;
	display: flex;
	align-items: center;
	justify-content: center;
	background: rgba(255, 255, 255, 0.15);
	border-radius: 20rpx;
	backdrop-filter: blur(10rpx);
	border: 1rpx solid rgba(255, 255, 255, 0.2);
	transition: all 0.3s ease;
	box-shadow: 0 4rpx 12rpx rgba(0, 0, 0, 0.1);
}

.back-button:active {
	background: rgba(255, 255, 255, 0.25);
	transform: scale(0.95);
	box-shadow: 0 2rpx 8rpx rgba(0, 0, 0, 0.15);
}

.back-icon {
	font-size: 32rpx;
	color: white;
	font-weight: 600;
	text-shadow: 0 1rpx 2rpx rgba(0, 0, 0, 0.1);
}

.header-title {
	color: white;
	font-size: 32rpx;
	font-weight: 600;
}



.header-actions {
	display: flex;
	align-items: center;
	gap: 15rpx;
}

.test-action {
	padding: 8rpx 12rpx;
	background: rgba(255, 255, 255, 0.15);
	border-radius: 20rpx;
	border: 1rpx solid rgba(255, 255, 255, 0.3);
}

.test-text {
	color: white;
	font-size: 20rpx;
	opacity: 0.9;
}

.header-action {
	padding: 12rpx 24rpx;
	background: rgba(255, 255, 255, 0.2);
	border-radius: 25rpx;
}

.action-text {
	color: white;
	font-size: 24rpx;
}

.summary-options {
	padding: 30rpx 20rpx;
	background: white;
	margin: 20rpx;
	border-radius: 20rpx;
	box-shadow: 0 8rpx 32rpx rgba(0, 0, 0, 0.1);
	flex-shrink: 0;
}

.option-header {
	margin-bottom: 20rpx;
}

.option-title {
	font-size: 28rpx;
	font-weight: 600;
	color: #333;
}

.options-grid {
	display: flex;
	gap: 15rpx;
}

.option-card {
	flex: 1;
	padding: 30rpx 20rpx;
	background: #f8f9fa;
	border-radius: 16rpx;
	text-align: center;
	transition: all 0.3s ease;
	border: 2rpx solid transparent;
}

.option-card.active {
	background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
	border-color: #667eea;
	transform: translateY(-4rpx);
	box-shadow: 0 12rpx 32rpx rgba(102, 126, 234, 0.3);
}

.option-icon {
	font-size: 40rpx;
	display: block;
	margin-bottom: 10rpx;
}

.option-label {
	font-size: 24rpx;
	font-weight: 500;
	color: #333;
	display: block;
	margin-bottom: 8rpx;
}

.option-card.active .option-label {
	color: white;
}

.option-desc {
	font-size: 20rpx;
	color: #999;
	line-height: 1.4;
	display: block;
}

.option-card.active .option-desc {
	color: rgba(255, 255, 255, 0.8);
}

/* 自定义日期范围选择 */
.custom-date-section {
	margin: 20rpx;
	background: white;
	border-radius: 20rpx;
	padding: 30rpx;
	box-shadow: 0 8rpx 32rpx rgba(0, 0, 0, 0.1);
	flex-shrink: 0;
}

.date-picker-row {
	display: flex;
	gap: 20rpx;
}

.date-picker-item {
	flex: 1;
}

.date-label {
	font-size: 24rpx;
	color: #666;
	display: block;
	margin-bottom: 10rpx;
}

.date-picker-input {
	display: flex;
	align-items: center;
	justify-content: space-between;
	padding: 20rpx;
	background: #f8f9fa;
	border-radius: 12rpx;
	border: 2rpx solid #e9ecef;
	transition: all 0.3s ease;
}

.date-picker-input:active {
	border-color: #667eea;
	background: rgba(102, 126, 234, 0.05);
}

.date-text {
	font-size: 26rpx;
	color: #333;
}

.picker-arrow {
	font-size: 24rpx;
	opacity: 0.6;
}

.summary-content {
	margin: 20rpx;
	margin-bottom: 0;
	background: white;
	border-radius: 20rpx 20rpx 0 0;
	flex: 1;
	overflow-y: auto;
	box-shadow: 0 8rpx 32rpx rgba(0, 0, 0, 0.1);
}

/* 加载状态 */
.loading-state {
	padding: 100rpx 40rpx;
	text-align: center;
}

.loading-animation {
	position: relative;
	margin-bottom: 40rpx;
}

.loading-circle {
	width: 80rpx;
	height: 80rpx;
	margin: 0 auto 30rpx;
	border: 4rpx solid #f0f0f0;
	border-top: 4rpx solid #667eea;
	border-radius: 50%;
	animation: spin 1s linear infinite;
}

.loading-dots {
	display: flex;
	justify-content: center;
	gap: 8rpx;
}

.dot {
	width: 12rpx;
	height: 12rpx;
	background: #667eea;
	border-radius: 50%;
	animation: bounce 1.4s infinite ease-in-out;
}

.dot1 { animation-delay: -0.32s; }
.dot2 { animation-delay: -0.16s; }

.loading-text {
	font-size: 28rpx;
	color: #333;
	display: block;
	margin-bottom: 15rpx;
}

.loading-tip {
	font-size: 24rpx;
	color: #999;
	display: block;
}

/* 总结结果 */
.summary-result {
	padding: 40rpx;
}

.result-header {
	text-align: center;
	margin-bottom: 40rpx;
	padding-bottom: 30rpx;
	border-bottom: 1rpx solid #f0f0f0;
}

.result-icon {
	font-size: 60rpx;
	display: block;
	margin-bottom: 15rpx;
}

.result-title {
	font-size: 32rpx;
	font-weight: 600;
	color: #333;
	display: block;
	margin-bottom: 10rpx;
}

.result-time {
	font-size: 24rpx;
	color: #999;
	display: block;
}

.result-meta {
	margin-top: 10rpx;
	display: flex;
	justify-content: center;
	gap: 10rpx;
}

.meta-tag {
	font-size: 24rpx;
	color: #666;
}

.meta-date {
	font-size: 24rpx;
	color: #999;
}

.summary-section {
	margin-bottom: 40rpx;
}

.section-title {
	font-size: 26rpx;
	font-weight: 600;
	color: #333;
	display: block;
	margin-bottom: 20rpx;
}

.stats-grid {
	display: grid;
	grid-template-columns: 1fr 1fr;
	gap: 20rpx;
	margin-bottom: 20rpx;
}

.stat-item {
	text-align: center;
	padding: 25rpx;
	background: #f8f9fa;
	border-radius: 12rpx;
}

.stat-number {
	font-size: 36rpx;
	font-weight: bold;
	color: #667eea;
	display: block;
	margin-bottom: 8rpx;
}

.stat-label {
	font-size: 22rpx;
	color: #666;
	display: block;
}

.analysis-content {
	margin-top: 15rpx;
}

.analysis-text {
	font-size: 26rpx;
	color: #333;
	line-height: 1.6;
	display: block;
}

.analysis-rich-text {
	font-size: 26rpx;
	color: #333;
	line-height: 1.6;
}

/* Markdown样式 */
.analysis-rich-text /deep/ h1,
.analysis-rich-text /deep/ h2,
.analysis-rich-text /deep/ h3 {
	font-weight: bold;
	margin: 20rpx 0 15rpx 0;
	color: #2c3e50;
}

.analysis-rich-text /deep/ h1 {
	font-size: 32rpx;
}

.analysis-rich-text /deep/ h2 {
	font-size: 30rpx;
}

.analysis-rich-text /deep/ h3 {
	font-size: 28rpx;
}

.analysis-rich-text /deep/ p {
	margin: 15rpx 0;
	line-height: 1.6;
}

.analysis-rich-text /deep/ strong {
	font-weight: bold;
	color: #2c3e50;
}

.analysis-rich-text /deep/ em {
	font-style: italic;
	color: #7f8c8d;
}

.analysis-rich-text /deep/ ul,
.analysis-rich-text /deep/ ol {
	margin: 15rpx 0;
	padding-left: 30rpx;
}

.analysis-rich-text /deep/ li {
	margin: 8rpx 0;
	line-height: 1.5;
}

.analysis-rich-text /deep/ blockquote {
	border-left: 4rpx solid #667eea;
	margin: 20rpx 0;
	background: #f8f9fa;
	padding: 15rpx 20rpx;
	border-radius: 8rpx;
}

.analysis-rich-text /deep/ code {
	background: #f1f2f6;
	padding: 4rpx 8rpx;
	border-radius: 4rpx;
	font-family: 'Courier New', monospace;
	font-size: 24rpx;
}

.suggestions-list {
	margin-top: 15rpx;
}

.suggestion-item {
	display: flex;
	align-items: flex-start;
	margin-bottom: 15rpx;
}

.suggestion-bullet {
	color: #667eea;
	font-size: 24rpx;
	margin-right: 12rpx;
	margin-top: 4rpx;
}

.suggestion-text {
	flex: 1;
	font-size: 24rpx;
	color: #333;
	line-height: 1.5;
}

.action-buttons {
	margin-top: 40rpx;
	display: flex;
	gap: 20rpx;
}

.action-btn {
	flex: 1;
	padding: 28rpx;
	border-radius: 16rpx;
	text-align: center;
	transition: all 0.3s ease;
}

.action-btn.secondary {
	background: #f8f9fa;
	border: 2rpx solid #e9ecef;
}

.action-btn.primary {
	background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}

.action-btn.secondary .btn-text {
	color: #666;
}

.action-btn.primary .btn-text {
	color: white;
}

.btn-text {
	font-size: 26rpx;
	font-weight: 500;
}

/* 错误状态 */
.error-state {
	padding: 100rpx 40rpx;
	text-align: center;
}

.error-icon {
	font-size: 120rpx;
	display: block;
	margin-bottom: 30rpx;
	opacity: 0.6;
}

.error-title {
	font-size: 32rpx;
	color: #333;
	font-weight: 500;
	display: block;
	margin-bottom: 15rpx;
}

.error-message {
	font-size: 26rpx;
	color: #999;
	line-height: 1.5;
	display: block;
	margin-bottom: 40rpx;
}

.error-action {
	background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
	padding: 28rpx 50rpx;
	border-radius: 25rpx;
	display: inline-block;
}

.error-action-text {
	color: white;
	font-size: 26rpx;
	font-weight: 500;
}

/* 空状态 */
.empty-state {
	padding: 100rpx 40rpx;
	text-align: center;
}

.empty-icon {
	font-size: 120rpx;
	display: block;
	margin-bottom: 30rpx;
	opacity: 0.6;
}

.empty-title {
	font-size: 32rpx;
	color: #333;
	font-weight: 500;
	display: block;
	margin-bottom: 15rpx;
}

.empty-subtitle {
	font-size: 26rpx;
	color: #999;
	line-height: 1.5;
	display: block;
	margin-bottom: 40rpx;
}

.empty-action {
	background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
	padding: 28rpx 50rpx;
	border-radius: 25rpx;
	display: inline-block;
}

.empty-action-text {
	color: white;
	font-size: 26rpx;
	font-weight: 500;
}

/* 动画 */
@keyframes spin {
	0% { transform: rotate(0deg); }
	100% { transform: rotate(360deg); }
}

@keyframes bounce {
	0%, 80%, 100% {
		transform: scale(0);
	}
	40% {
		transform: scale(1);
	}
}
</style> 